<!-- 
    graph-data.htm 
-->

<html>
<body>
    <h4>${jedisPool}</h4>

    <table border="1">
        <tr>
            <td><a href="?sort=HostApp">#</a></td>
            <td><a href="?sort=Type">Type</a></td>
            <td><a href="?sort=Host">Host</a></td>
            <td><a href="?sort=ApplicationName">ApplicationName</a></td>
            <td><a href="?sort=From">From</a></td>
            <td><a href="?sort=To">To</a></td>
            <td><a href="?sort=KeyCount">KeyCount</a></td>
            <td>操作 (Clear Before)</td>
        </tr>

        <#assign _sort>${(RequestParameters["sort"])!}</#assign>

        <#if !(_sort??) || (_sort?length lt 1)> 
            <#assign _sort>KeyCount</#assign> 
        </#if>

        <#assign _sum=0 />

        <#list tableData?sort_by(_sort)?reverse as each>
        <#assign _sum=_sum + each.KeyCount />

        <tr>
            <td>${each_index+1}</td>
            <td>${each.Type}</td>
            <td>${each.Host}</td>
            <td>${each.ApplicationName}</td>
            <td>${each.From}</td>
            <td>${each.To}</td>
            <td>${each.KeyCount?c}</td>
            <td>
                <!-- Clear -->
                <input type="hidden" id="from_${each_index}" value="0" />
                <!-- Before -->
                <input class="clear_before_time" id="to_${each_index}" />
                <input type="button" value="清理" onclick="do_clear(${each_index},'${each.Type}','${each.Host}','${each.ApplicationName}')" />
            </td>
        </tr>
        </#list>

        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>总计</td>
            <td>${_sum}</td>
            <td></td>
        </tr>
    </table>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
    var now = new Date( new Date().getTime() - 3 * 24 * 60 * 60 * 1000 ) ; 

    var time = "" + now.getFullYear()

    if ( now.getMonth()<9 ) {
        time += "0" + ( now.getMonth() + 1 ) ;
    } else {
        time += now.getMonth() + 1 ;
    }
    if ( now.getDate()<10 ) {
        time += "0" + now.getDate();
    } else {
        time += now.getDate();
    }
    if ( now.getHours()<10 ) {
        time += "0" + now.getHours();
    } else {
        time += now.getHours();
    }
    if ( now.getMinutes()<10 ) {
        time += "0" + now.getMinutes();
    } else {
        time += now.getMinutes();
    }

    $(".clear_before_time").val(time);

    window.do_clear = function (index, Type, Host, ApplicationName){
        $(".clear_before_time").val($("#to_"+index).val()); // 同步值到所有input

        $.ajax({
            url : "graph-data-clear.json",
            type : "POST",
            data : {
                "Type" : Type,
                "Host" : Host,
                "ApplicationName" : ApplicationName,
                "from" : $("#from_"+index).val(),
                "to" : $("#to_"+index).val()
            }
        }).done(function(response) {
            alert(JSON.stringify(response));
        });
    }
});
</script>
</body>
</html>
